package thread;

import java.util.Scanner;
/**
 * sleep阻塞
 * 线程提供了一个静态方法:
 * static void sleep(long ms)
 * 该方法可以让执行这个方法的线程进入阻塞状态(BLOCK状态)指定毫秒，超时后线程会自动回
 * 到RUNNABLE状态再次开始并发执行
 */
public class SleepDemo {
    public static void main(String[] args) {
        /*
            做一个简易倒计时程序
            要求:程序启动后输入一个数字,从该数字开始每秒递减并输出,当到0时输出时间到!
         */
        Scanner scan = new Scanner(System.in);
        System.out.print("请输入时间设定:");
        int times = scan.nextInt();
        try {

            for (int i = times; i >0 ; i--) {
                    System.out.println("倒计时:" + i );
                    Thread.sleep(1000);
            }
            System.out.println("时间到!!!!!!!!!!!!!!!!!!");
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }




        /*System.out.println("程序开始了...");
        try {
            for (int i = 1; i <= 5; i++) {
                Thread.sleep(1000);
                System.out.println("排队中........" + i + "s");
            }
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println("程序结束了!");*/

    }
}
